package com.cloud.check.api.service.impl;

import com.cloud.check.api.bean.JgJgdxGthBasicMsgBean;
import com.cloud.check.api.entity.JgJgdxGthBasicMsg;
import com.cloud.check.api.mapper.JgJgdxGthBasicMsgMapper;
import com.cloud.check.api.service.JgJgdxGthBasicMsgService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

/**
 * @program: quokka-server
 * @description: ${description}
 * @author: sl
 * @create: 2019-09-19 14:59
 **/
@Service
@Transactional
public class JgJgdxGthBasicMsgServiceImpl implements JgJgdxGthBasicMsgService {

    @Autowired
    private JgJgdxGthBasicMsgMapper jgJgdxGthBasicMsgMapper;

    public PageInfo<JgJgdxGthBasicMsg> searchBusiness(JgJgdxGthBasicMsgBean jgJgdxGthBasicMsgBean){
        PageInfo<JgJgdxGthBasicMsg> page = null;
        Example example = new Example(JgJgdxGthBasicMsg.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isEmpty(jgJgdxGthBasicMsgBean.getUniSCID()) && StringUtils.isEmpty(jgJgdxGthBasicMsgBean.getTraName())) {
            page = PageHelper.startPage(jgJgdxGthBasicMsgBean.getPageNum(), jgJgdxGthBasicMsgBean.getPageSize())
                    .doSelectPageInfo(() -> {
                        jgJgdxGthBasicMsgMapper.findAllBusiness();
                    });
        } else {
            if (StringUtils.isNotEmpty(jgJgdxGthBasicMsgBean.getUniSCID())) {
                criteria.andLike("uniSCID", jgJgdxGthBasicMsgBean.getUniSCID() + "%");
            }
            if (StringUtils.isNotEmpty(jgJgdxGthBasicMsgBean.getTraName())) {
                criteria.andLike("traName", "%" + jgJgdxGthBasicMsgBean.getTraName() + "%");
            }
            page = PageHelper.startPage(jgJgdxGthBasicMsgBean.getPageNum(), jgJgdxGthBasicMsgBean.getPageSize())
                    .doSelectPageInfo(() -> {
                        jgJgdxGthBasicMsgMapper.selectByExample(example);
                    });
        }
        return page;
    }
}
